package com.heima.ThreadPool.ForkJoin;

import java.util.concurrent.ForkJoinPool;

/**
 * @Author: Ethan Yankang
 * @Program: 面试必会代码
 * @Date: 2024-08-30 15:53
 **/


public class ForkJoin {
    public static void main(String[] args) {
        long[] array = new long[1000_0000];//创建1000W数据
        for (int i = 0; i < array.length; i++) {
            array[i]=i+1;
        }
//        创建任务
        RecursiveTask recursiveTask = new RecursiveTask(array, 0, array.length);
//        创建ForkJoinPool并执行任务
        /*
         * @description 将之前的任务放进ForkJoinPool里面去
         * @params
         * @return
         */

        ForkJoinPool forkJoinPool = new ForkJoinPool();
        Long result = forkJoinPool.invoke(recursiveTask);

        System.out.println("结果是：Sum+="+result);

//        关闭ForkJoinPool
        forkJoinPool.shutdown();
    }
}

